
package proyecto1;


public class FormularioEmpresa extends javax.swing.JDialog {

    int contador = 0;

    public FormularioEmpresa(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        mostrarDato();
        this.setLocationRelativeTo(null);// ventana al centro
        this.setVisible(true);
    }

    public void mostrarDato() {
        EmpresasClientes ec = new EmpresasClientes();
        ec = (EmpresasClientes) (Main.datosEm.get(contador));
        TextoCodigo.setText(ec.getCodigo());
        TextoRut.setText(ec.getRut());
        TextoNombre.setText(ec.getNombre());
        TextoTelefono.setText(ec.getTelefono());
        TextoFax.setText(ec.getFax());
        TextoCorreoC.setText(ec.getCorreoContacto());
        TextoDireccion.setText(ec.getDireccion());


        numero.setText((contador + 1) + "/" + Main.contadorE);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        TextoCodigo = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        TextoRut = new javax.swing.JLabel();
        Siguiente = new javax.swing.JButton();
        TextoAtras = new javax.swing.JButton();
        TextoVolver = new javax.swing.JButton();
        numero = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        TextoNombre = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        TextoDireccion = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        TextoTelefono = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        TextoFax = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        TextoCorreoC = new javax.swing.JLabel();
        BotonBorrar = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Codigo: ");

        TextoCodigo.setText("jLabel2");

        jLabel3.setText("Rut: ");

        TextoRut.setText("jLabel4");

        Siguiente.setText("Siguiente");
        Siguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SiguienteActionPerformed(evt);
            }
        });

        TextoAtras.setText("Atrás");
        TextoAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextoAtrasActionPerformed(evt);
            }
        });

        TextoVolver.setText("Volver Menú");
        TextoVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextoVolverActionPerformed(evt);
            }
        });

        numero.setText("jLabel2");

        jLabel2.setText("Nombre: ");

        TextoNombre.setText("jLabel4");

        jLabel4.setText("Direccion: ");

        TextoDireccion.setText("jLabel5");

        jLabel5.setText("Teléfono: ");

        TextoTelefono.setText("jLabel6");

        jLabel6.setText("Fax:");

        TextoFax.setText("jLabel7");

        jLabel7.setText("Correo de Contacto: ");

        TextoCorreoC.setText("jLabel8");

        BotonBorrar.setText("Borrar Empresa");
        BotonBorrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonBorrarActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
        jLabel8.setText("Empresa");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(221, 221, 221)
                        .add(jLabel8)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(numero))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel4)
                                    .add(jLabel5)
                                    .add(jLabel6)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(jLabel2)
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jLabel3)
                                            .add(jLabel1))))
                                .add(70, 70, 70)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(TextoFax)
                                    .add(TextoTelefono)
                                    .add(TextoDireccion)
                                    .add(TextoNombre)
                                    .add(TextoRut)
                                    .add(TextoCodigo)))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(TextoVolver)
                                    .add(jLabel7))
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(TextoCorreoC))
                                    .add(layout.createSequentialGroup()
                                        .add(33, 33, 33)
                                        .add(BotonBorrar)))
                                .add(51, 51, 51)
                                .add(TextoAtras, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(Siguiente)))
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(numero, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(46, 46, 46)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(TextoCodigo))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(TextoRut)
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(TextoNombre))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(TextoDireccion))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(TextoTelefono))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(TextoFax))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(TextoCorreoC))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 113, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(TextoVolver)
                    .add(Siguiente)
                    .add(TextoAtras)
                    .add(BotonBorrar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void SiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SiguienteActionPerformed
    if (contador < Main.contadorE - 1) {
        contador++;
        mostrarDato();
    }
}//GEN-LAST:event_SiguienteActionPerformed

private void TextoAtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextoAtrasActionPerformed
    if (contador > 0) {
        contador--;
        mostrarDato();
    }
    
}//GEN-LAST:event_TextoAtrasActionPerformed

private void TextoVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextoVolverActionPerformed
    this.setVisible(false);
}//GEN-LAST:event_TextoVolverActionPerformed

private void BotonBorrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBorrarActionPerformed
//para borrar
Main.datosEm.remove(contador);
if(contador!=0){
 contador--;   
}

Main.contadorE--;
if(Main.contadorE!=0){ // si es distinto es porque quedan personas   
   mostrarDato(); 
}else {
    this.setVisible(false); // para que se cierre la ventana
}

}//GEN-LAST:event_BotonBorrarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormularioEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormularioEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormularioEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormularioEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                FormularioEmpresa dialog = new FormularioEmpresa(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonBorrar;
    private javax.swing.JButton Siguiente;
    private javax.swing.JButton TextoAtras;
    private javax.swing.JLabel TextoCodigo;
    private javax.swing.JLabel TextoCorreoC;
    private javax.swing.JLabel TextoDireccion;
    private javax.swing.JLabel TextoFax;
    private javax.swing.JLabel TextoNombre;
    private javax.swing.JLabel TextoRut;
    private javax.swing.JLabel TextoTelefono;
    private javax.swing.JButton TextoVolver;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel numero;
    // End of variables declaration//GEN-END:variables
}
